<template>
    <section class="login">
        <div class="login-image">
            <el-image :src="background"></el-image>
        </div>
        <div class="login-model">
            <div style="margin-bottom: 60px;">{{ tabTitle }}</div>
            <el-form :model="form" status-icon :rules="rules" ref="form" label-width="100px" style="width: 260px" label-position="top">
                <el-form-item label="" prop="username" style="margin-bottom: 22px">
                    <el-input v-model="form.username" autocomplete="off" placeholder="请输入账号"></el-input>
                </el-form-item>
                <el-form-item label="" prop="password" style="margin-bottom: 22px">
                    <el-input type="password" placeholder="请输入密码" v-model="form.password" @keyup.enter.native="handleSubmit" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSubmit" style="width: 100%; margin-top: 40px" :loading="loginLoading">登陆</el-button>
                </el-form-item>
            </el-form>
        </div>
    </section>
</template>
<script>
    import background from "@/assets/images/login.png"
    export default {
        name: 'LoginForm',
        props: {
            source: ""
        },
        watch: {

        },
        data () {
            return {
                background,
                form: {
                    username: '',
                    password: ''
                },
                tabTitle: this.source=="login-visitor" ? "访客登录" : (this.source=="login-factory" ? "供应商管理" : ""),
                loginLoading: false,
                rules: {
                    username: [{ required: true, message: "请输入账号", trigger: "blur" }],
                    password: [{ required: true, message: "请输入密码", trigger: "blur" }],
                },
            }
        },
        computed: {

        },
        methods: {
            handleSubmit () {
                this.loginLoading = true;
                this.$emit('on-login', {
                    username: this.form.username,
                    password: this.form.password,
                    source_from: this.source == 'login-visitor' ? 'visitor' :( this.source == 'login-factory' ? 'gc' : 'null')
                });
            }
        },
        mounted: function(){

        }
    }
</script>
<style scoped>
    .login {
        width: 100%;
        height: 100vh;
        background: #000c17;
        background-image: linear-gradient(to right bottom, #000c17, #041629);
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 500px;
    }
    .login-image {
        width: 50%;
    }
    .login-model {
        font-size: 20px;
        /*font-weight: 800;*/
        text-align: center;
        color:#f5f7fa;
        border-radius: 4px;
        /*background-color: #ffffff;*/
        box-shadow: 8px 8px 20px 1px #ebeef5;
        margin-left: 6%;
        padding: 4% 2%;
    }
    input {
        background: #000000;
        color: #304156;
    }
</style>
